<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<title>admin</title>
	<link rel="stylesheet" href="">
    <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://cdn.bootcss.com/jquery/1.11.2/jquery.min.js"></script>
    <script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
	<script src="https://cdn.bootcss.com/vue/2.4.4/vue.js"></script>
	<script src="https://cdn.bootcss.com/axios/0.16.2/axios.min.js"></script>
    <link rel="stylesheet" type="text/css" href="/css/admin.css">
</head>
<body>
<!-- <?php $html="<script>alert(454545);</script>"; ?>
{{$html}} -->
    <div class="container">
        <div class="row">
            <div class="col-md-12">
             @if (session('msg'))
                 <div class="alert {{(session('code')==200)?'alert-success':'alert-danger'}} alert-dismissible fade in" role="alert">
                    <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    {{ session('msg') }}
                 </div>
                @endif
                <div class="panel panel-default">
                    <div class="panel-heading panel-heading-custom">
                        <h3 class="panel-title panel-title-custom">
                        {!!Request::get('keyword')?'<span class="glyphicon glyphicon-search" aria-hidden="true"></span> 关键字<code>'.Request::get('keyword').'</code>搜索结果':'<span class="glyphicon glyphicon-list-alt" aria-hidden="true"></span> 订单列表'!!}
                         <span style="float:right">
                            <form class="navbar-form panel-form" method="get" action="/dashboard/item">
                                <input type="text" id="keyword"  name="keyword"  value="" class="form-control" placeholder="请输入名称">
                                <button id="search_btn" onclick="turnPage(1);" class="btn btn-info" data-loading-text="提交中..." type="button"><span class="glyphicon glyphicon-search" aria-hidden="true"></span> 查询</button>
                               <a href="{{route('order.create')}}" class="btn btn-primary"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span> 添加</a>
                                <a href="javascript:void(0);" onclick="addBox();" class="btn btn-success"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span> 测试更新</a>
                                <a href="javascript:void(0);" onclick="box();" class="btn btn-primary"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Options</a>
                            </form>
                        </span>
                        </h3>
                    </div>
                    <div class="table-responsive">
                        <table class="table table-hover">
                        <thead>
                            <tr>
                                <th>ID</th>
                                <th>名称</th>
                                <th>类型</th>
                                <th>创建时间</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                        @forelse ($items as $info)
                        <tr>
                            <td>{{$info->id}}</td>
                            <td><span data-toggle="tooltip" data-placement="bottom" title="{{$info->name}}">{{str_limit($info->name,20)}}</span></td>
                            <td>{{$info->type}}</td>
                            <td>{{$info->created_at}}</td>
                            <td>
                                <div class="btn-group btn-group-xs" role="group" aria-label="...">
                                <a href="/admin/order/{{$info->id}}/edit" class="btn btn-success">修改</a>
                                <a href="{{route('order.show',$info->id)}}" class="btn btn-primary">查看</a>
                                <a onclick="delBox({{$info->id}});" href="javascript:void(0);" class="btn btn-danger">删除</a>
                                </div>
                            </td>
                        </tr>
                        @empty
                            <tr>
                                <td colspan="4" style="text-align: center">暂无数据</td>
                            </tr>
                       @endforelse
                        </tbody>
                    </table>   
                    </div> 
                    <div class="panel-footer">
                        <span style="float:left" class="text-left">共 {{$items->count()}} 条信息</span>
                        <span style="float: right" class="text-right">{!!$items->appends(['keyword' => Request::get('keyword'),'type'=>Request::get('type')])->render() ?: '暂无分页'!!}</span>
                        <div class="clearfix "></div>
                     </div>
                </div>
            </div>    
        </div>    
    </div>   
</body>
</html>
<script type="text/javascript">
function box(){
    $.ajax({
        url: '/admin/order/9',
        type: 'OPTIONS',//OPTIONS
        dataType: 'json',
    })
    .done(function(data) {
        console.log(data);
        console.log("success");
    })
    .fail(function() {
        console.log("error");
    })
    .always(function() {
        console.log("complete");
    });
    
}

//put 添加
function addBox()
{
    $.ajax({
        url: '/admin/order/9',
        type: 'patch',//put
        dataType: 'json',
        data: {_token: '{{csrf_token()}}',name:"<?php echo time();?>",type:2},
    })
    .done(function(data) {
        if(data.code==200)
        {
            alert(data.msg);
            window.location.reload();
        }
        else{alert(data.msg);}
        console.log("success");
    })
    .fail(function() {
        console.log("error");
    })
    .always(function() {
        console.log("complete");
    });
    
}
//delete 删除
function delBox(id){
if(confirm('确认删除吗?'))
{
    $.ajax({
        url: '/admin/order/'+id,
        type: 'DELETE',
        dataType: 'json',
        data: {_token: '{{csrf_token()}}'},
    })
    .done(function(data) {
        if(data.code==200)
        {
            alert(data.msg);
            window.location.reload();
        }
        else{alert(data.msg);}
        console.log("success");
    })
    .fail(function() {
        console.log("error");
    })
    .always(function() {
        console.log("complete");
    });
    
}
}
</script>